<?php
	
class Infografico{
	
	var $id;
	var $html_info;
	var $nome;
	var $img_fundo;
	var $cor_fundo;
	var $status;
	var $professor_id;

	/* Getters and Setters */
	public function setId($value){
		$this->id = $value;
	}
	public function getId(){
		return $this->id;
	}
	
   	public function setNome($value){
		$this->nome = $value;
	}
	public function getNome(){
		return $this->nome;
	}
	
   	public function setHtml_info($value){
		$this->html_info = $value;
	}
	public function getHtml_info(){
		return $this->html_info;
	}
	
   	public function setImg_fundo($value){
		$this->img_fundo = $value;
	}
	public function getImg_fundo(){
		return $this->img_fundo;
	}
	
   	public function setCor_fundo($value){
		$this->cor_fundo = $value;
	}
	public function getCor_fundo(){
		return $this->cor_fundo;
	}
	
   	public function setStatus($value){
		$this->status = $value;
	}
	public function getStatus(){
		return $this->status;
	}	
	
   	public function setProfessorId($value){
		$this->professor_id = $value;
	}
	public function getProfessorId(){
		return $this->professor_id;
	}
	/* Getters and Setters */

	
	function salvaInfo($object){
		
		$con = new Conexao();
		 	 		 
		$query2 = "INSERT INTO infografico 
						 (pessoa_id,
						  nome,
						  status)
				   VALUES
					   ('".$object->professor_id."',
					    '".$object->nome."',
						'".$object->status."')";
					   
		$con->query($query2);
				 
	    return $con->lastID();
	
	}
	
	function atualizarInfo($object){
	
		$con = new Conexao();
		
		$query = "UPDATE infografico SET
						  html_info = '".$object->html_info."'
				  WHERE id_infografico = ".$object->id."";
				 
	    return $con->query($query);
	}
	
	function exibeInfo($object){
	
		$con = new Conexao();
		
		$addWhere = " WHERE 1 = 1 ";
		
		if($_SESSION['tipo_pessoa']=="P"){ 
			$addWhere .= " AND pessoa_id = ".$object->professor_id." ";
		}
		
		if($object->id != ""){
			$addWhere .= " AND id_infografico = '".$object->id."' ";
		}
		
		$query = "SELECT id_infografico,
						 nome,
						 img_fundo,
						 cor_fundo,
						 html_info,
						 status,
						 pessoa_id
				  FROM infografico
				  $addWhere";	
		
		$result = $con->query($query);
		
		return $con->fetchArray($result);
		
	}
	
	function exibeListaInfo($object){
	
		$con = new Conexao();		
		
		$addWhere = "";
		
		if($_SESSION['tipo_pessoa']=="P"){ 
			$addWhere .= " WHERE i.pessoa_id = ".$object->professor_id." ";
		}else{
			$addWhere .= " WHERE p.escola_id = ".$_SESSION['escola_id']." ";
		}
		
		$query = "SELECT i.id_infografico,
					     i.nome,
					     i.img_fundo,
					     i.cor_fundo,
					     i.html_info,
					     i.status,
					     i.pessoa_id
				  FROM infografico i
				  INNER JOIN pessoas p ON p.id_pessoa = i.pessoa_id				  
				  $addWhere";	
		
		$result = $con->query($query);
		
		$resultado = "";
		
		while( $row = $con->fetchArray($result) ){
			$resultado .= "<div style='background:#FFF;border:1px solid #C1CDC1;width:220px;height:22px;margin-bottom:2px;font-weight:bold;'><a href='javascript:void(0);' onclick='exibeInfo(".$row['id_infografico'].")'>".$row['nome']."</a></div>";				
		}
		
		return $resultado;	
		
	}

	function deletarInfo($object){
		
		$con = new Conexao();
		 	 		 
		$query = "DELETE FROM infografico WHERE id_infografico = ".$object->id;
					   
		return $con->query($query);
	
	}
	
	function buscaNumeracaoInfo($object){
	
		$con = new Conexao();
		
		$query = "SELECT id_infografico, numero_info FROM infografico WHERE id_infografico = '".$object->id."'";			
		$result = $con->query($query);
		$row = $con->fetchArray($result);
		
		$valor = $row['numero_info']+1;
		
		$query1 = "UPDATE infografico SET numero_info = '".$valor."' WHERE id_infografico = '".$object->id."'";			
		$con->query($query1);
		
		return $valor;
		
	}
}

?>